from django.db import models

# Create your models here.
class LoginUser(models.Model):
    loginname = models.CharField(max_length=40)
    loginpass = models.CharField(max_length=40)

class Emp(models.Model):
    empno = models.AutoField(primary_key=True)
    ename = models.CharField(max_length=20)
    sal = models.FloatField()
    hiredate = models.DateField()
    dept = models.ForeignKey(to='Dept',on_delete=models.CASCADE)

    def to_dict(self):
        return {'empno':self.empno,'ename':self.ename,'sal':self.sal,'hiredate':self.hiredate.strftime('%Y-%m-%d'),'dept':self.dept.to_dict(),'dept_id':self.dept_id}

class Dept(models.Model):
    deptno = models.AutoField(primary_key=True)
    dname = models.CharField(max_length=40)
    loc = models.CharField(max_length=40)

    def to_dict(self):
        return {'deptno':self.deptno,'dname':self.dname,'loc':self.loc}

class Order(models.Model):
    '''订单'''
    orderid = models.CharField(verbose_name='订单号',max_length=64)
    title = models.CharField(verbose_name='名称',max_length=32)
    price = models.FloatField(verbose_name='价格')
    status_choices = (
        (1,'待支付'),
        (2,'已支付')
    )
    status = models.SmallIntegerField(verbose_name='状态',choices=status_choices,default=1)
    emp = models.ForeignKey(to=Emp,on_delete=models.CASCADE)